﻿using NineSeas.Extensions;
using Orchard.ContentManagement;
using Orchard.Tags.Models;
using System;
using System.Linq;
using Contrib.Taxonomies.Fields;
namespace NineSeas.Models
{
    public class BookPart: ContentPart<BookPartRecord>, ILikeable, IViewCountable
    {
        public int AuthorId
        {
            get { return Record.AuthorId; }
            set { Record.AuthorId = value; }
        }

        public string Name
        {
            get { return Record.Name; }
            set { Record.Name = value; }
        }
        public string NameOnUrl
        {
            get { return Record.NameOnUrl; }
            set { Record.NameOnUrl = value; }
        }
        public string Introduction
        {
            get { return Record.Introduction; }
            set { Record.Introduction = value; }
        }

        public DateTime? CreatedDate
        {
            get { return Record.CreatedDate; }
            set { Record.CreatedDate = value; }
        }

        public DateTime? LastUpdatedDate
        {
            get { return Record.LastUpdatedDate; }
            set { Record.LastUpdatedDate = value; }
        }
        public string ImageUrl
        {
            get { return Record.ImageUrl; }
            set { Record.ImageUrl = value; }
        }
        public string ImageStoragePath
        {
            get { return Record.ImageStoragePath; }
            set { Record.ImageStoragePath = value; }
        }
        public int TotalViews
        {
            get { return Record.TotalViews; }
            set { Record.TotalViews = value; }
        }
        public int TotalLikes
        {
            get { return Record.TotalLikes; }
            set { Record.TotalLikes = value; }
        }
        public int WeekViews
        {
            get { return Record.WeekViews; }
            set { Record.WeekViews = value; }
        }
        public int WeekLikes
        {
            get { return Record.WeekLikes; }
            set { Record.WeekLikes = value; }
        }

        public BookStatusEnum Status
        {
            get { return (BookStatusEnum)Record.Status; }
            set { Record.Status = (int)value; }
        }

        string ILikeable.Dimension
        {
            get
            {
                return Constants.VotingDimensions.BookLike;
            }
        }
        string IViewCountable.Dimension
        {
            get
            {
                return Constants.VotingDimensions.BookView;
            }
        }

        public TagsPart Tags
        {
            get
            {
                return this.As<TagsPart>();
            }
        }

        public TaxonomyField Categories
        {
            get
            {
                return (TaxonomyField)this.Fields.First(f => String.Compare(f.Name, Constants.Taxonomies.Categories) == 0);
            }
        }
    }
}